<?php	if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
 * Tokaban Standard System
 *
 * Tokaban framework for PHP
 *
 * @package		ap_standard_system
 * @author		Tokaban R&D Team
 * @copyright	Copyright (c) 2009, Tokaban, Inc. 
 * @since		Version 2.0
 *   
 */ 
   
// ------------------------------------------------------------------------
class payment extends Controller 
{	
	var $m_language 		= ''; 
	var $m_nid_user 		= ''; 
			 
	var $m_link_page		= ''; 
	var $m_event_index		= ''; 
	var $m_view_index		= '';
	 
	var $m_error_message	= '';
	var $m_form_title		= '';
	// Form login
	var $m_txt_user_name	= ''; 
	var $m_txt_password		= '';
	
	//Form contact
	var $m_txt_cfullname	= '';
	var $m_txt_caddress		= '';
	var $m_txt_nphone		= '';
	var $m_txt_cemail		= '';
	var $m_txt_cnote		= '';
	
	var $nid_order			= '';
	
	var $m_display_login	= 'block';
	var $m_display_contact	= 'none';
	  
	// ------------------------------------------------------------------------
	
/** 
 * Constructor
 *
 * Load cac thu vien can su dung cho class 
 *
 * @access	public 
 */	
function payment()
	{ 
		// 
		// DINH NGHIA BAT BUOC TRONG TAT CA CAC CONTROLLER.
		// KHONG DUOC TU Y THAY DOI CAC DONG THONG TIN BEN DUOI. 
		//
		parent::Controller();  
		session_start();
		$this->load->database();
		$this->load->helper('ap_db');	
		$this->load->helper('ap_function');
		$this->load->helper('ap_html');
		$this->load->helper('ap_view');
		$this->load->helper('ap_object');
		$this->load->helper('ap_module');
		$this->load->helper('ap_captcha_helper');			
		
		// 
		// CAC DINH NGHIA CAN THIET KHAC
		// 
		$this->load->model('payment_model');
		
	} 
	
function null_cart()
	{
		$data['title']			= '';
		$data['tags']			= '';
		$data['description']	= '';
		
		$data['menu_sec']		= '';
		$data['menu_cat']		= '';
		$data['g_ishome']				= 0;
		$this->load->view('null_cart', $data);
	}	
	// ------------------------------------------------------------------------
	
/**
 * Goi tuan tu cac ham theo dung quy dinh ve luong du lieu
 * 
 * @access	public
 */		
function index()
	{
		$this->view();
	}		
	
	// ------------------------------------------------------------------------

function login()
	{
		$this->m_language = Fget_userdata('session_user_language');										
		$this->load->language('tokaban',$this->m_language);
		// Your code at here
		
		$this->m_display_login				= 'block';
		$this->m_display_contact			= 'none';
		
		if(isset($_POST['txt_user_name']))
				$this->m_txt_user_name 		= $_POST['txt_user_name'];
		
		if(isset($_POST['txt_password']))
				$this->m_txt_password 		= $_POST['txt_password'];
		
		if($this->check_valid_login()===TRUE)
			redirect ('order_complete');
		
		
		$this->view();
		
	}

function contact()
	{
		$this->m_language = Fget_userdata('session_user_language');										
		$this->load->language('ap',$this->m_language);
		
		$this->m_display_login				= 'none';
		$this->m_display_contact			= 'block';
		
		// Your code at here
		if(isset($_POST['txt_cfullname']))
				$this->m_txt_cfullname 		= $_POST['txt_cfullname'];
		
		if(isset($_POST['txt_caddress']))
				$this->m_txt_caddress 		= $_POST['txt_caddress'];
			
		if(isset($_POST['txt_nphone']))
				$this->m_txt_nphone 		= $_POST['txt_nphone'];
		
		if(isset($_POST['txt_cemail']))
				$this->m_txt_cemail 		= $_POST['txt_cemail'];
		
		if(isset($_POST['txt_cnote']))
				$this->m_txt_cnote 		= $_POST['txt_cnote'];
		if($this->insert_contact() == TRUE )
			redirect ('order_complete');
		
		$this->view();
		
		
	}

function view()
	{
	
		$data['display_login']		= $this->m_display_login;
		$data['display_contact']	= $this->m_display_contact;
		
		$data['txt_cfullname']		= $this->m_txt_cfullname;
		$data['txt_caddress']		= $this->m_txt_caddress;
		$data['txt_nphone']			= $this->m_txt_nphone;
		$data['txt_cemail']			= $this->m_txt_cemail;
		$data['txt_cnote']			= $this->m_txt_cnote;
		
		$data['txt_user_name']	= $this->m_txt_user_name;
		$data['error_message']	= $this->m_error_message;
		
		$data['title']			= '';
		$data['tags']			= '';
		$data['description']	= '';
		
		$data['menu_sec']		= '';
		$data['menu_cat']		= '';
		$data['g_ishome']				= 0;
		$this->load->view('payment',$data);
	}

//
// DINH NGHIA CAC HAM LOGIC CAN THIET KHAC TAI DAY
//
private function check_valid_login()
	{
		// Kiem tra user dang nhap khong duoc phep rong
		if (trim($this->m_txt_user_name)=='')
		{
			$this->m_error_message = 'Tên đăng nhập không đúng';
			return FALSE;
		}
		// Kiem tra thong tin mat khau khong duoc phep rong
		if (trim($this->m_txt_password)=='')
		{
			$this->m_error_message = 'Mật khẩu đăng nhập không đúng';
			return FALSE;
		}
				
		// Kiem tra thong tin user va mat khau ton tai trong he thong du lieu
		$nid_user = Obj_is_user($this->m_txt_user_name,$this->m_txt_password);
		
		if ($nid_user=='invalid')
			{
				$this->m_error_message =  'Thông tin đăng nhập không đúng'; 
				return FALSE;
			}
		else // Xu ly truong hop dang nhap thong tin thanh cong
			{
				
				// Xac dinh bo sung cac thong tin login		
				$obj_user_row = Obj_get_user_datarow($nid_user);
				if($obj_user_row['nstatus'] == 0)
				{
					$this->m_error_message = 'Tài khoản đã bị khóa';
					return FALSE;
				}
				$str_user_fullname= $obj_user_row['cfirstname'] . ' ' . $obj_user_row['cmiddlename'] . ' ' . $obj_user_row['clastname'];

				Fset_userdata('session_nid_customer',$nid_user);
				Fset_userdata('session_customer_name',$obj_user_row['customerid']);
				Fset_userdata('session_full_name',$str_user_fullname);
				
				Fset_userdata('session_customer_full_name',$str_user_fullname);
				Fset_userdata('session_customer_address', $obj_user_row['caddress']);
				Fset_userdata('session_customer_phone', $obj_user_row['chandphone']);			
				Fset_userdata('session_customer_email', $obj_user_row['cemail']);
				Fset_userdata('session_customer_note', $obj_user_row['cnote']);
							
				return TRUE;
			}							
	}
	
/**
 *-------------------------------------------------------------------
 * @creator 		: Hoang Minh An - an_hm87@tokaban.com

 * @finished date	: 2009/12/13
 * @description		: Insert du lieu vao tcity
 * @access	        : private
 *
 * @param string	: None
 * 					: 
 * @return string	: None
 *-------------------------------------------------------------------
 * @editor   	    : 
 * @finished date	: 
 * @editing content	: 
 *-------------------------------------------------------------------
 */		
private function insert_contact()
	{			       
			Fset_userdata('session_customer_full_name', $this->m_txt_cfullname);
			Fset_userdata('session_customer_address', $this->m_txt_caddress);
			Fset_userdata('session_customer_phone', $this->m_txt_nphone);			
			Fset_userdata('session_customer_email', $this->m_txt_cemail);
			Fset_userdata('session_customer_note', $this->m_txt_cnote);
			// Goi phuong thuc cap nhat thong tin vao database.	
			return TRUE;
	}

// END do_init class
}		
/* End of file do_init.php */
/* Location: controller/do_init.php */